package com.gateway.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * 自定义全局过滤器
 * 本地接口不会触发全局过滤器，只有经过路由的接口才会执行过滤器
 * */
@Component
public class CustomGlobalFilter implements GlobalFilter, Ordered {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        System.out.println("自定义的全局过滤器---前置！");
        Mono<Void> filter = chain.filter(exchange);
        System.out.println("自定义的全局过滤器---后置！");
        return filter;
    }

    @Override
    public int getOrder() {
        return 0;
    }
}
